package com.xinsoft.controller.wms;

import com.alibaba.fastjson.JSONObject;
import com.xinsoft.common.Response;
import com.xinsoft.constant.Const;
import com.xinsoft.entity.dto.ScmStockParam;
import com.xinsoft.entity.po.MesStation;
import com.xinsoft.entity.po.ScmStockFrozen;
import com.xinsoft.service.ScmStockFrozenService;
import com.xinsoft.service.ScmStockHisService;
import com.xinsoft.service.ScmStockService;
import com.xinsoft.validator.ValidatorUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 库存
 * @folder 云供应链/仓库管理/库存查询
 */
@RestController
@RequestMapping("/scm/stock")
public class ScmStockController {

    @Autowired
    private ScmStockService scmStockService;

    @Autowired
    private ScmStockHisService scmStockHisService;

    @Autowired
    private ScmStockFrozenService scmStockFrozenService;

    /**
     * 库存查询
     */
    @PostMapping("/pageList")
    public Response<?> pageList(@RequestBody ScmStockParam param) {
        JSONObject data = new JSONObject();
        // 分页列表
        data.put("pageList",scmStockService.findPageListByParam(param));
        // 合计行
        data.put("total",scmStockService.findTotalByParam(param));
        return Response.succeed(data);
    }


    /**
     * 库存查询
     */
    @PostMapping("/list")
    public Response<?> list(@RequestBody ScmStockParam param) {
        JSONObject data = new JSONObject();
        // 分页列表
        data.put("list",scmStockService.findListByParam(param));
        // 合计行
        data.put("total",scmStockService.findTotalByParam(param));
        return Response.succeed(data);
    }

    /**
     * 历史库存查询
     */
    @PostMapping("/hisList")
    public Response<?> hisList(@RequestBody ScmStockParam param) {
        JSONObject data = new JSONObject();
        // 分页列表
        data.put("list",scmStockHisService.findListByParam(param));
        // 合计行
        data.put("total",scmStockHisService.findTotalByParam(param));
        return Response.succeed(data);
    }

    /**
     * 冻结库存查询
     */
    @PostMapping("/frozenList")
    public Response<?> frozenList(@RequestBody ScmStockParam param) {
        JSONObject data = new JSONObject();
        // 分页列表
        data.put("list",scmStockFrozenService.findListByParam(param));
        // 合计行
        data.put("total",scmStockFrozenService.findTotalByParam(param));
        return Response.succeed(data);
    }



    /**
     * 新增
     */
    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/addScmStockFrozen")
    public Response<?> add(@RequestBody ScmStockFrozen scmStockFrozen) {
        // 参数校验
        ValidatorUtils.validateEntity(scmStockFrozen);
        return Response.succeed(scmStockFrozenService.addMesStation(scmStockFrozen));
    }

    /**
     * 更新
     */
    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/editScmStockFrozen")
    public Response<?> edit(@RequestBody  ScmStockFrozen scmStockFrozen) {
        // 参数校验
        ValidatorUtils.validateEntity(scmStockFrozen);
        return Response.succeed(scmStockFrozenService.editMesStation(scmStockFrozen));
    }

    /**
     * 删除
     */
    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/delScmStockFrozen")
    public Response<?> del(@RequestBody List<Integer> ids) {
        scmStockFrozenService.del(ids);
        return Response.succeed();
    }

}
